<?php $this->load->view('includes/head.php'); ?>
<div class="container">
	<div class="row" id="new-task">
		<?php echo validation_errors(); ?>
		<?php if ($valid): ?>
			<div class="alert alert-success alert-dismissible" role="alert">
			  <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
			  Your task has been successfully created.
			</div>
		<?php endif ?>
		<div class="col-sm-12" spellcheck="true">

			<h1> Add New Task </h1>
			<hr>
			<?php 
				echo form_open('manage/create_task', array('role' => 'form'));
			?>
				

			<div class="row">
				<div class="col-sm-9">
					<div class="form-group">
						<label for="title">Title: 
							<a href="#" data-toggle="popover" rel="popover" data-content="Please enter a short description for this task.">
								<i class="fa fa-question-circle"></i>
							</a>
							</label>
						<?php

							$title = array(
								'name' => 'title',
								'id' => 'title',
								'type' => 'text',
								'placeholder' => 'Enter Title',
								'class' => 'form-control',
								'spellcheck' => 'true',
								'autofocus' => TRUE,
								'value' => set_value('title', '')
	            			);	

echo form_input($title)
						?>
						
					</div>
			
					<div class="form-group">
						<label for="content">Task Description:</label>
                        <textarea class="form-control textarea" name="content" id="desc"> <?php echo set_value('content'); ?></textarea>
					</div>
				</div>					
								

				<!--- -============================================================= -->

				<div class="col-sm-3" style="margin-top: 24px;">
					<div class="panel panel-default">
					  <div class="panel-heading">Basic Information</div>
					  <div class="panel-body">
							<div class="form-group">
								<label for="date">Date Due: 
									<a href="#" data-toggle="popover" rel="popover" data-content="Select the due date for the assigned task.">
										<i class="fa fa-question-circle"></i>
									</a>
								</label>
                                    <input type="text" class="form-control" name="date" placeholder="Select Date" value="<?php echo set_value('date'); ?>" />
							</div>

							<div class="form-group">
								<label for="status">Status: 
									<a href="#" data-toggle="popover" rel="popover" data-content='Select a status for this task, or leave the default selection of "Not Started".'>
										<i class="fa fa-question-circle"></i>
									</a>
								</label>
								<select class="form-control" placeholder="-Select-" name="status">
                                    <option value="1" <?php echo set_select('status','1'); ?>>Not Started</option>
                                    <option value="2" <?php echo set_select('status','2'); ?>>In Progress</option>
                                    <option value="3" <?php echo set_select('status','3'); ?>>Completed</option>
								</select>
							</div>

							<div class="form-group">
								<label for="priority">Priority: 
									<a href="#" data-toggle="popover" rel="popover" data-content='Select a priority for this task, or leave the default selection of "Low".'>
										<i class="fa fa-question-circle"></i>
									</a>
								</label>
								<select class="form-control" placeholder="-Select-" name="priority">
                                                                <option value="1" <?php echo set_select('priority','1'); ?>>Low</option>
                                                                <option value="2" <?php echo set_select('priority','2'); ?>>Medium</option>
                                                                <option value="3" <?php echo set_select('priority','3'); ?>>High</option>
								</select>
							</div>
						</div>
					</div>
				</div>
			</div>
			<!--- -============================================================= -->
			<div class="row">
				<div class="col-sm-12">
					<h3>Assigning Roles</h3>
				</div>
			</div>
			
			<!--- -============================================================= -->

			<div class="row">
				<div class="col-sm-3">
					<div class="form-group">
						<label for="responsible">Responsible: 
							<a href="#" data-toggle="popover" rel="popover" data-content="Assign at least 1 user as the person Responsible for this task. These user(s) are responsible for performing the work assigned.">
								<i class="fa fa-question-circle"></i>
							</a>
						</label>
					</div>
				
					<div class="form-group">
						
						<select name="responsible[]" class="form-control" multiple>
							<?php 
								foreach ($users as $user) {
									$id = intval($user->id, 10);
									$value = set_value('responsible[]', $id);
									$name = $user->first_name . ' ' . $user->last_name;
									echo '<option value="'.$value.'"'. set_select("responsible", $id ) . '>'. $name .'</option>';
								};
							?>
"<?php
echo set_value('responsible[]', $id);
?>"
						</select>

					</div>
				</div>	
        
				<div class="col-sm-3">	
					<div class="form-group">
						<label for="accountable">Accountable: 
							<a href="#" data-toggle="popover" rel="popover" data-content="Only 1 person may ultimately be Accountable for a given task. This is typically the person in charge of the project/task who would be held accountable should the work not get performed on time or properly.">
								<i class="fa fa-question-circle"></i>
							</a>
						</label>
					</div>
					<div class="form-group">
						<select name="accountable[]" class="form-control">
							<?php 

								foreach ($users as $user) {
									$id = intval($user->id, 10);
									$value = set_value('accountable[]', $id);
									$name = $user->first_name . ' ' . $user->last_name;
									$selected = (in_array($id, $this->input->post("informed"))) ? 'selected' : '';
									if ($selected != '') {
										echo '<option value="'.$value.'" '.$selected.'>'. $name .'</option>';
									}else{
										$default = ($user_id == $id) ? 'selected' : '';
										echo '<option value="'.$value.'" '. $default . '>'. $name .'</option>';
									}
								};
							?>
						</select>
					</div>	
				</div>

				<div class="col-sm-3">	
					<div class="form-group">
						<label for="consulted">Consulted: 
							<a href="#" data-toggle="popover" rel="popover" data-content="(Optional) - You may assign multiple users to be consulted on a task. These users are typically subject matter experts who can provide the advice needed for successful task completion.">
								<i class="fa fa-question-circle"></i>
							</a>
						</label>
					</div>
					<div class="form-group">
						<select name="consulted[]" class="form-control" multiple>
							<?php 
								foreach ($users as $user) {
									$id = intval($user->id, 10);
									$value = set_value('consulted[]', $id);
									$name = $user->first_name . ' ' . $user->last_name;
									echo '<option value="'.$value.'" '.(in_array($id,$this->input->post("consulted")) ? 'selected':'').'>'. $name .'</option>';
								};
							?>
						</select>
					</div>
				</div>

				<div class="col-sm-3">					
					<div class="form-group">
						<label for="informed">Informed: 
							<a href="#" data-toggle="popover" rel="popover" data-content="(Optional) - You may assign multiple users to be informed of task progress. These users are typically associated with managers or individuals with an interest in this task’s progress. The individuals listed here will receive status update emails whenever the task is updated.">
								<i class="fa fa-question-circle"></i>
							</a>
						</label>
					</div>
					<div class="form-group">
						
						<select name="informed[]" class="form-control" multiple>
							<?php 
								foreach ($users as $user) {
									$id = intval($user->id, 10);
									$value = set_value('informed[]', $id);
									$name = $user->first_name . ' ' . $user->last_name;
									echo '<option value="'.$value.'"'.(in_array($id,$this->input->post("informed")) ? 'selected':'').'>'. $name .'</option>';
								};
							?>
						</select>
						
					</div>
				</div>
			</div> <?php //Close Row ?>

			<hr>

			<div class="row bottom-margin">
				<div class="col-sm-12">
					 <button type="submit" id="submit-task" class="btn btn-info btn-lg pull-right">Create Task</button>
				</div>
			</div>

			<?php echo form_close(); ?>

		</div>
	</div>
</div>


		